﻿@model Nop.Web.Models.Catalog.ProductReviewsModel
@using Nop.Web.Framework;
@{
    Layout = "~/Views/Shared/_Root.cshtml";

    //title
    Html.AddTitleParts(T("PageTitle.ProductReviews").Text);
}
<div class="product-reviews-page">
    <div class="page-title">
        <a href="@Url.RouteUrl("Product", new { productId = Model.ProductId, SeName = Model.ProductSeName })">@Model.ProductName</a>
    </div>
    <div class="clear">
    </div>
    @if (Model.AddProductReview.SuccessfullyAdded)
    {
        @Model.AddProductReview.Result
    }
    else
    {
        <div class="write-review" id="review-form">
            @using (Html.BeginForm())
            {
                <strong>@T("Reviews.Write")</strong>
                <div>
                    @Html.LabelFor(model => model.AddProductReview.Title)
                    @Html.TextBoxFor(model => model.AddProductReview.Title, new { @class = "review-title" })
                    @Html.ValidationMessageFor(model => model.AddProductReview.Title)
                </div>
                <div>
                    @Html.LabelFor(model => model.AddProductReview.ReviewText)
                    @Html.TextAreaFor(model => model.AddProductReview.ReviewText, new { @class = "review-text" })
                    @Html.ValidationMessageFor(model => model.AddProductReview.ReviewText)
                </div>   
                
                <div data-role="fieldcontain">
                    <fieldset data-role="controlgroup" data-type="horizontal">
                        <legend>@Html.LabelFor(model => model.AddProductReview.Rating)</legend>
                        @for (int i = 1; i <= 5; i++)
                        {
                            string ratingControlId = "addproductrating" + i.ToString();
            
                            <input type="radio" name="@Html.FieldNameFor(model => model.AddProductReview.Rating)" id="@(ratingControlId)" value="@(i.ToString())" @(i == Model.AddProductReview.Rating ? Html.Raw(" checked=\"checked\"") : null) />
                            <label for="@(ratingControlId)">@(i.ToString())</label>
                        }
                    </fieldset>
                </div>
                <div class="message-error">
                    @Html.ValidationSummary(true)
                </div>                    
                <input type="submit" id="add-review" name="add-review" value="@T("Reviews.SubmitButton")" />
                    
            }
        </div>
    }
    <div class="clear">
    </div>
    @if (Model.Items.Count > 0)
    {
        <div class="product-review-list">
            <div>
                <strong>@T("Reviews.ExistingReviews")</strong>
            </div>
            <ul data-role="listview" data-inset="true" data-filter="false">
                @foreach (var review in Model.Items)
                {
                    int ratingPercent = review.Rating * 20;
                
                    <li>
                        <div class="product-review-item">
                            <div class="review-title">
                                @review.Title
                            </div>
                            <div class="product-review-box">
                                <div class="rating">
                                    <div style="width: @(ratingPercent)%">
                                    </div>
                                </div>
                            </div>
                            <div class="clear">
                            </div>
                            <div class="review-text">
                                @Html.Raw(Nop.Core.Html.HtmlHelper.FormatText(review.ReviewText, false, true, false, false, false, false))
                            </div>
                            <div class="clear">
                            </div>
                            <div class="review-info">
                                <div>
                                    @T("Reviews.From"):
                                    @if (review.AllowViewingProfiles)
                                    {
                                        <a href="@Url.RouteUrl("CustomerProfile", new { id = review.CustomerId })">@(review.CustomerName)</a>
                                    }
                                    else
                                    {
                                        @review.CustomerName
                                    }
                                </div>
                                <div>
                                    @T("Reviews.Date"):
                                    @review.WrittenOnStr
                                </div>
                            </div>
                        </div>
                    </li>
                }
            </ul>
        </div>
    }
</div>
